﻿using System;
using System.Collections;
using System.Text;

namespace passitumi
{
	/**
	 * This class acts as a data structure which contains information
	 * regarding peers found using a similar service. This class is used
	 * by forming an arraylist of PeerContacts.
	 */
	public class PeerContact
	{
		private string serviceName;
		private ArrayList ipAddress = new ArrayList();
		private short port;

		/**
		 * Constructor which will establish the peer's information
		 */
		public PeerContact(string serviceName, string ipAddress, short port)
		{
			this.serviceName = serviceName;
			this.ipAddress.Add(ipAddress);
			this.port = port;
		}

		/**
		 * Method to return the service name of this peer.
		 */
		public string getServiceName()
		{
			return this.serviceName;
		}

		/**
		 * Method to return the IP address of this peer.
		 */
		public ArrayList getIpAddress()
		{
			return this.ipAddress;
		}

		/**
		 * Method to update the ip addresses of a peer contact.
		 */
		public void setIpAddress(ArrayList ipAddress)
		{
			this.ipAddress = ipAddress;
		}

		/**
		 * Method to return the port number of this peer.
		 */
		public short getPort()
		{
			return this.port;
		}

		/**
		 * Public method that adds a new ip address for this peer.
		 */
		public void addIpAddress(string ipAddress)
		{
			this.ipAddress.Add(ipAddress);
		}

		/**
		 * Public method to remove an ip address from the list of the peer's ip addresses.
		 */
		public bool removeIpAddress(string ipAddress)
		{
			for (int i = 0; i < this.ipAddress.Count; i++)
			{
				if (this.ipAddress[i].ToString() == ipAddress)
				{
					this.ipAddress.RemoveAt(i);
					return true;
				}
			}
			return false;
		}
	}
}
